package at.guigu.service.impl;

import at.guigu.domain.po.User;
import at.guigu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class UserServiceImplTestTwo {
    @Autowired
    private IUserService userService;
    private User InsertUser(int i) {
        User user = new User();
        user.setUsername("user_" + 1);
        user.setPassword("123456");
        user.setPhone("17736789882");
        user.setBalance(200);
        user.setInfo("{\"age\": 20, \"intro\": \"优秀小子\", \"gender\": \"female\"}");
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        return user;
    }

    // 批量插入十万条用户数据
    void test() {
        List<User> userList = new ArrayList<User>(1000);
        for (int i = 0; i < 10000; i++) {
            userList.add(InsertUser(i));
            if (i % 1000 == 0) {
                userService.saveBatch(userList);
                userList.clear();
            }
        }
    }
}
